<?php
/**
 * Created by PhpStorm.
 * User: alei
 * Date: 11/4/2017 AD
 * Time: 16:15
 */
require_once('discuzstr.php');
if (! function_exists('ddg')) {
	/**
	 * Dump the passed variables and end the script.
	 *
	 * @param  mixed
	 * @return void
	 */
	function ddg()
	{
		array_map(function ($x) {
			(new \Illuminate\Support\Debug\Dumper)->dump($x);
		}, func_get_args());
	}
}

/**
 * 返回json
 *
 * @param string｜array $msg 返回的消息
 * @param boolean $status 是否成功
 */
if( ! function_exists('responseJson')) {
	function responseJson($msg,$data=[], $status = false)
	{
		if(!is_array($msg)){
			$msg=[$msg];
		}
		return response()->json([
			'status' => $status ? '1' : '0',
			'data' => $data,
			'message' => !empty($msg) ? $msg : []
		]);
	}
}

if( ! function_exists('dintval')) {
	function dintval($int, $allowarray = false)
	{
		$ret = intval($int);
		if($int == $ret || !$allowarray && is_array($int)) return $ret;
		if($allowarray && is_array($int)) {
			foreach($int as &$v) {
				$v = dintval($v, true);
			}
			return $int;
		} elseif($int <= 0xffffffff) {
			$l = strlen($int);
			$m = substr($int, 0, 1) == '-' ? 1 : 0;
			if(($l - $m) === strspn($int,'0987654321', $m)) {
				return $int;
			}
		}
		return $ret;
	}
}

if( ! function_exists('remain_time')) {
	function remain_time($time)
	{
		$days = intval($time / 86400);
		$time -= $days * 86400;
		$hours = intval($time / 3600);
		$time -= $hours * 3600;
		$minutes = intval($time / 60);
		$time -= $minutes * 60;
		$seconds = $time;
		return array((int)$days, (int)$hours, (int)$minutes, (int)$seconds);
	}
}

if( ! function_exists('getCurUser')) {
	function getCurUser(){
        #①先判断是否已经登录
        if(!isset($_SESSION)){
			session_start();
		}
		if(!isset($_SESSION['uid'])){
			return array();
        }
		else{
			return array('uid'=>$_SESSION['uid'],'user_name'=>$_SESSION['user_name']);
		}
	}	
}


use App\Models\Mysql\pre_common_member_profile;
if( ! function_exists('isCurUserCertified')) {
	function isCurUserCertified(){
		$curUser = getCurUser();
		$curUid = $curUser['uid'];
        if($curUid==0){
			return false;
		}
		else{
			return pre_common_member_profile::isUserCertified($curUid);
		}
	}	
}

if( ! function_exists('avatarUrl')) {
    function avatarUrl($uid, $size = 'middle')
    {
        $size = in_array($size, array('big', 'middle', 'small')) ? $size : 'middle';
		$discuzRoot=config('applqyw.discuz_root');
		$ucenterRoot=$discuzRoot.'uc_server/';
		$ucenterurl=config('applqyw.discuz_server_url').'uc_server/';
		$uid = sprintf("%09d", $uid);
		$dir1 = substr($uid, 0, 3);
		$dir2 = substr($uid, 3, 2);
		$dir3 = substr($uid, 5, 2);
		$file = 'data/avatar/'.$dir1.'/'.$dir2.'/'.$dir3.'/'.substr($uid, -2).'_avatar_'.$size.'.jpg';
		$file = (is_readable($ucenterRoot.$file)) ? $ucenterurl.$file : $ucenterurl.'images/noavatar_'.$size.'.gif';
		return $file;
    }
}

?>
